home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2005 November
/
WNnov2005.iso
/
Windows
/
Equipement
/
hMailServer
/
hMailServer-4.1-Build-136.exe
/
{app}
/
Addons
/
Squirrelmail Plugins
/
hmailserver_changepass
/
options.php
< prev
next >
Wrap
PHP Script
|
2005-03-14
|
11KB
|
358 lines
<?php
/*
* Change hMailServer MySQL Password plugin 1.0
*
*/
chdir ('..');
if (!defined('SM_PATH')) define('SM_PATH','../');
// include compatibility plugin
//
if (file_exists('./plugins/compatibility/functions.php'))
include_once('./plugins/compatibility/functions.php');
else if (file_exists('../plugins/compatibility/functions.php'))
include_once('../plugins/compatibility/functions.php');
// get global variables for versions of PHP < 4.1
//
if (!compatibility_check_php_version(4, 1)) {
global $HTTP_SERVER_VARS, $HTTP_POST_VARS;
$_SERVER = $HTTP_SERVER_VARS;
$_POST = $HTTP_POST_VARS;
}
global $color;
global $split_username_query, $split_username_expression,
$split_username_domain_field, $debug;
$isForceChange = stristr($_SERVER['PHP_SELF'], 'right_main.php')
|| stristr($_SERVER['PHP_SELF'], 'webmail.php');
if (!$isForceChange)
{
if (compatibility_check_sm_version(1, 3))
{
include_once (SM_PATH . 'include/validate.php');
include_once (SM_PATH . 'functions/page_header.php');
include_once (SM_PATH . 'functions/imap.php');
include_once (SM_PATH . 'include/load_prefs.php');
include_once (SM_PATH . 'functions/i18n.php');
include_once (SM_PATH . 'config/config.php');
include_once (SM_PATH . 'functions/strings.php');
include_once (SM_PATH . 'functions/imap.php');
}
else
{
include_once ('../src/validate.php');
include_once ('../functions/page_header.php');
include_once ('../functions/imap.php');
include_once ('../src/load_prefs.php');
include_once ('../functions/i18n.php');
include_once ('../config/config.php');
include_once ('../functions/strings.php');
include_once ('../functions/imap.php');
}
}
// get flag that tells us if this is a password submission attempt...
//
if (isset($_POST['plugin_hmailserver_changepass']))
$plugin_hmailserver_changepass = $_POST['plugin_hmailserver_changepass'];
// determine URL for redirection if Cancel is pressed
// (non https if the flag is on, otherwise, use what
// was already there)
//
$cancelLocation = 'http' . (isset($_SERVER["HTTPS"]) ? 's' : '');
ereg("(^.*/).*", $_SERVER['REQUEST_URI'], $regs);
$cancelLocation .= '://' . $_SERVER['HTTP_HOST']
. $regs[1] . '../../src/options.php?optmode=submit&plugin_hmailserver_changepass=0';
// if a password change is given, check its validity
//
if (isset($plugin_hmailserver_changepass))
{
$Messages = hmailserver_changepass_check();
// the above only returns if password wasn't changed
// so if we came from webmail.php, must redirect to
// right_main.php (need to pass messages along...)
//
if (stristr($_SERVER['PHP_SELF'], 'webmail.php'))
{
$location = $_SERVER['PHP_SELF'];
$location = str_replace('webmail.php', 'right_main.php', $location);
$location .= '?messages=';
foreach($Messages as $message) $location .= urlencode($message . '||');
header('Location: ' . $location);
exit(0);
}
}
// don't display page header if we got a successful
// password change (No error messages exist and a
// password was submitted. Cannot send output before
// header() call)
//
if (!isset($Messages) && isset($cp_oldpass) && $cp_oldpass)
{
// do nothing
}
else
{
// if not in force password change mode, we
// still need to send a page header
//
if (!$isForceChange)
{
displayPageHeader($color, 'None', 'document.forms[0].elements["cp_oldpass"].focus();');
echo '<br>';
}
echo '<table width=95% align=center cellpadding=2 cellspacing=2 border=0>';
echo '<tr><td bgcolor="';
if (!$isForceChange)
echo $color[0] . '">';
else
echo $color[2] . '">';
}
echo '<center><b>';
echo _("Change Password");
echo '</b></center></td>';
if (isset($Messages) && count($Messages)) {
echo "<tr><td>\n";
foreach ($Messages as $line) {
echo htmlspecialchars($line) . "<br>\n";
}
echo "</td></tr>\n";
}
?><tr><td>
<?php
if ($_SERVER['PHP_SELF']) {
$location=$_SERVER['PHP_SELF'];
} else {
$location="../plugins/hmailserver_changepass/options.php";
}
$location = str_replace('right_main.php', 'webmail.php', $location);
?>
<form method=post action="<?php echo $location; ?>">
<table>
<tr>
<th align=right><?php echo _("Old Password"); ?>:</th>
<td><input type=password name=cp_oldpass value="" size=20></td>
</tr>
<tr>
<th align=right><?php echo _("New Password"); ?>:</th>
<td><input type=password name=cp_newpass value="" size=20></td>
</tr>
<tr>
<th align=right><?php echo _("Verify New Password"); ?>:</th>
<td><input type=password name=cp_verify value="" size=20></td>
</tr>
<tr>
<td align=right colspan=2>
<input type="hidden" name="plugin_hmailserver_changepass" value="1">
<input type=submit value="<?php echo _("Submit"); ?>">
<?php
if (!$isForceChange)
echo '<input type=button value="' . _("Cancel") . '" onClick="document.location=\'' . $cancelLocation . '\'"'
. ' name="plugin_hmailserver_changepass_cancel">';
?>
</td>
</tr>
</table>
</td></tr>
</tr></table>
</body></html>
<?php
exit(0);
function hmailserver_changepass_check() {
global $cp_oldpass, $cp_newpass, $cp_verify, $key, $onetimepad;
global $plugin_change_ldappass;
// get global variables for versions of PHP < 4.1
//
if (!compatibility_check_php_version(4, 1)) {
global $HTTP_SESSION_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS;
$_SESSION = $HTTP_SESSION_VARS;
$_POST = $HTTP_POST_VARS;
$_COOKIE = $HTTP_COOKIE_VARS;
}
$Messages = array();
$password = OneTimePadDecrypt($_COOKIE['key'], $_SESSION['onetimepad']);
$cp_oldpass = $_POST['cp_oldpass'];
$cp_newpass = $_POST['cp_newpass'];
$cp_verify = $_POST['cp_verify'];
if ($cp_oldpass == '')
array_push($Messages, _("You must type in your old password."));
if ($cp_newpass == '')
array_push($Messages, _("You must type in a new password."));
if ($cp_verify == '')
array_push($Messages,
_("You must also type in your new password in the verify box."));
if ($cp_newpass != '' && $cp_verify != $cp_newpass)
array_push($Messages,
_("Your new password does not match the verify password."));
if ($cp_oldpass != '' && $cp_oldpass != $password)
array_push($Messages, _("Your old password is not correct."));
if ($cp_oldpass == $cp_newpass)
array_push($Messages, _("Your new password must be different than your old password."));
if (count($Messages))
return $Messages;
return hmailserver_changepass_go($password);
}
function hmailserver_changepass_go($password) {
global $split_username_query, $split_username_expression,
$split_username_domain_field, $debug, $update_clear_passwd_field;
// get global variables for versions of PHP < 4.1
//
if (!compatibility_check_php_version(4, 1)) {
global $HTTP_SESSION_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS;
$_SESSION = $HTTP_SESSION_VARS;
$_SERVER = $HTTP_SERVER_VARS;
$_POST = $HTTP_POST_VARS;
$_COOKIE = $HTTP_COOKIE_VARS;
}
$Messages = array();
$cp_newpass = $_POST['cp_newpass'];
$username = $_SESSION['username'];
$base_uri = $_SESSION['base_uri'];
$onetimepad = $_SESSION['onetimepad'];
$key = $_COOKIE['key'];
$user = $username;
if ($split_username_query)
{
list($user, $domain) = preg_split('/' . $split_username_expression . '/', $username);
}
// Extract domain part from email address
$iAtPos = strpos($username, '@');
$DomainName = substr($username, $iAtPos + 1);
$hCOMApp = new COM("hMailServer.Application");
$obDomain = $hCOMApp->Domains->ItemByName($DomainName);
if (!isset($obDomain))
{
array_push($Messages, _("Can not fetch domain object.!"));
return $Messages;
}
$obAccount = $obDomain->Accounts->ItemByAddress($username);
if (!isset($obAccount))
{
array_push($Messages, _("Can not fetch account object.!"));
return $Messages;
}
$sOldPassword = $obAccount->Password();
// Check that it matches ...
$sOldPasswordEntry = $_POST['cp_oldpass'];
$hCOMUtilities = new COM("hMailServer.Utilities");
// MD5 the entered password.
$sOldPasswordEntry = $hCOMUtilities->MD5($sOldPasswordEntry);
if ($sOldPassword != $sOldPasswordEntry)
{
array_push($Messages, _("Strange, your old password does not match the database... rejecting."));
return $Messages;
}
// OK, we should change it.
$obAccount->Password = $cp_newpass;
// Save the change.
$obAccount->Save();
// Write new cookies for the password
$onetimepad = OneTimePadCreate(strlen($cp_newpass));
$_SESSION['onetimepad'] = $onetimepad;
$key = OneTimePadEncrypt($cp_newpass, $onetimepad);
setcookie('key', $key, 0, $base_uri);
// no longer using https:
// (unless the flag is off, in which case we don't care - just
// use what was already there)
//
$location = 'http' . (isset($_SERVER["HTTPS"]) ? 's' : '');
ereg("(^.*/).*", $_SERVER['REQUEST_URI'], $regs);
$location .= '://' . $_SERVER['HTTP_HOST'];
if (strstr($_SERVER['REQUEST_URI'], 'right_main.php')
|| strstr($_SERVER['REQUEST_URI'], 'webmail.php'))
$location .= $regs[1] . 'right_main.php?optmode=submit&plugin_hmailserver_changepass=1';
else
$location .= $regs[1] . '../../src/options.php?optmode=submit&plugin_hmailserver_changepass=1';
header("Location: $location");
exit(0);
}
?>